package com.dd.stack.file.pojo.DO;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dd.stack.file.pojo.VO.FileVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/4/1 0:57
 * @Description 文件上传和下载 && 文件到导入和导出
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("ops_server_file")
public class FileDO {
    @ApiModelProperty("数据库id")
    @TableId(type = IdType.AUTO)
    private Long id;
    @ApiModelProperty("文件名")
    private String fileName;
    @ApiModelProperty("文件全路径")
    private String fileWholePath;
    @ApiModelProperty("文件大小 单位Byte")
    private Long fileSize;
    @ApiModelProperty("文件上传时间 数据库自动生成")
    private LocalDateTime createTime;
    @ApiModelProperty("数据库行数据更新时间")
    private LocalDateTime updateTime;

    public FileVO convert2VO() {
        FileVO fileVO = new FileVO();
        BeanUtils.copyProperties(this, fileVO);
        // 转换为KB
        fileVO.setFileSize(fileSize / 1024);
        return fileVO;
    }
}
